package com.sbxBase.controller;

import com.sbxBase.service.UserNoticeService;
import com.common.entity.Result;
import com.common.entity.sbxBase.UserNotice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

/**
 * @Author: 何剑
 * @Date: 2023/3/13
 * @Note:
 **/
@RestController
@RequestMapping("/userNotice")
@Api(tags = "用户公告")
public class UserNoticeController {
    @Resource
    private UserNoticeService userNoticeService;

    @PostMapping
    @ApiOperation("新增用户公告")
    public Result saveUserNotice(@RequestBody UserNotice userNotice) {
        userNoticeService.saveUserNotice(userNotice);
        return Result.success();
    }

    @GetMapping
    @ApiOperation("用户获取自己的公告信息")
    public Result pageUserNotice(@ApiParam("分页下标") @RequestParam(defaultValue = "1", required = false) Long pageIndex,
                                 @ApiParam("每页大小") @RequestParam(defaultValue = "10", required = false) Long pageSize,
                                 @ApiParam("是否已读") @RequestParam(defaultValue = "false", required = false) Boolean isRead,
                                 @ApiParam("事件") @RequestParam(required = false) String event,
                                 @ApiParam("排序字段") @RequestParam(required = false, defaultValue = "created") String orderByName,
                                 @ApiParam("正序 /倒序") @RequestParam(required = false, defaultValue = "true") Boolean orderBy) {

        return Result.page(userNoticeService.pageUserNotice(pageIndex, pageSize, isRead, event,orderByName,orderBy));
    }

    @PutMapping
    @ApiOperation("已读")
    public Result readUserNotice(@RequestBody Set<String> noticeIds) {
        userNoticeService.readUserNotice(noticeIds);
        return Result.success();
    }

}
